<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Sample</title>
<meta name="viewport"
            content="width=device-width, initial-scale=1.0">
<meta name="HandheldFriendly" content="true">
</head>
<body>
<canvas id="myCanvas" width="400" height="200"
        style="border:1px dashed #c3c3c3;">
   这里放置的内容用于浏览器不支持Canvas的情况
</canvas>
<script>
var canvas = document.getElementById("myCanvas");
if (canvas && canvas.getContext) {
   var cxt = canvas.getContext("2d");
   // 创建image
   var img = new Image();
   img.src = "images/icon_ch.png";
   // 当图片加载完毕再绘制
   img.onload = function (event){
      // 创建模式
      var pattern = cxt.createPattern(img, "repeat");
      // 指定模式
      cxt.fillStyle = pattern;
      // 绘图
      cxt.fillRect(0,0,400,200);
   }
}
</script>
</body>
</html>
